package com.saasitems.admin.web.controller;

import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.saasitems.admin.dao.ManagerUserMapper;
import com.saasitems.admin.model.ManagerUser;
import com.saasitems.admin.service.ManagerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/15.
 */
@Controller
public class IndexController {

    @Autowired
    private ManagerUserService managerUserService;

    @RequestMapping(value="index",method= RequestMethod.GET)
    public ModelAndView i() {
//        managerUserService.insert();
        managerUserService.selectAll();
        return new ModelAndView("admin/index");
    }

    @RequestMapping(value="admin/index",method= RequestMethod.GET)
    public ModelAndView index() {
        return new ModelAndView("admin/index");
    }

    @RequestMapping(value="admin/qiniutoken",method= RequestMethod.GET)
    @ResponseBody
    public Object qiniutoken() {
        String accessKey = "8BF-iUVfK3h8Qxwm17hdgcIvSdPVsUC20YihJExa";
        String secretKey = "B9xwE5OsO7dK9HuvGv4ExfhK2s_DcNfic7HgQ0wa";
        String bucketName = "kudianedu";
        Zone z = Zone.autoZone();
        Configuration c = new Configuration(z);
        UploadManager uploadManager = new UploadManager(c);
        Auth auth = Auth.create(accessKey, secretKey);
        String token = auth.uploadToken(bucketName);

        Map<String, String> m = new HashMap<String, String>();
        m.put("uptoken", token);
        return m;
    }
}
